from MsgProcess import MsgProcess, MsgType
import time,os
import RPi.GPIO as GPIO
from threading import Thread

class Switch(MsgProcess):
    def Start(self, message):
        Thread(target=self.Text).start()

    def Text(self, message={}):
        pin=31
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        
        GPIO.setup(pin,GPIO.OUT)
        for x in [1,2,3,4,5]:
            GPIO.output(pin,0)
            time.sleep(1)

        GPIO.setup(pin,GPIO.IN)
 
        key=0#
        while 1 :
            if GPIO.input(pin)==1 and key==0:#
                self.send(MsgType=MsgType.Text, Receiver="ControlCenter", Data="暂停")
                os.popen(r'sudo killall mpg123 > /dev/null 2>&1')
                key=1#
                
            if GPIO.input(pin)==0:#
                key=0#


            time.sleep(0.1)        
